import { Component, OnInit, ViewChild } from '@angular/core';
import { _HttpClient } from '@delon/theme';
import { GridComponent, SupDic, HttpService } from 'lbf';
import { SFComponent, SFSchema } from '@delon/form';
import { STColumn } from '@delon/abc';
import { Router, NavigationExtras } from '@angular/router';
import { NzMessageService } from 'ng-zorro-antd';

@Component({
  selector: 'app-zwybpub-rwjs',
  templateUrl: './rwjs.component.html',
})
export class ZwybpubRwjsComponent implements OnInit {
  LS_DAD010: any; //事项编码
  constructor(
    private supdic: SupDic,
    private router: Router,
    private lbservice: HttpService,
    public msgSrv: NzMessageService,
  ) {}
  queryFormData: any;
  getparams: NavigationExtras;
  columns: STColumn[] = [
    {
      title: '主事项名称',
      index: 'DAD017',
      dic: 'DAD017',
      width: '10px',
      fixed: 'left',
    },
    { title: '环节', index: 'DAD024', dic: 'DAD024', width: '60px' },
    { title: '子事项名称', index: 'DAD031', width: '50px' },
    { title: '申请方类型', index: 'DAD036', dic: 'DAD036', width: '70px' },
    { title: '申请证件类型', index: 'DAD074', dic: 'DAD074', width: '70px' },
    { title: '申请证件号码', index: 'DAD070', dic: 'DAD070', width: '70px' },
    { title: '申请者名称', index: 'DAD075', width: '70px' },
    { title: '开始时间', index: 'DAD096', type: 'date', width: '100px' },
    { title: '原操作员', index: 'AAE015', width: '100px' },
    {
      title: '操作区',
      width: '50px',
      fixed: 'right',
      buttons: [
        {
          text: '接收',
          click: (record: any) => this.rwjs(record),
        },
        {
          text: '拒绝',
          click: (record: any) => this.rwjj(record),
        },
      ],
    },
  ];
  params = {
    sname: 'query_rwzy',
    form: {},
  };

  @ViewChild('st', { static: true }) st: GridComponent;
  ngOnInit() {}

  _onReuseInit(): void {
    this.query();
  }

  query() {
    this.st.reload();
  }
  //任务接受过程
  rwjs(record) {
    this.lbservice
      .lbservice('rwjs_update', {
        para: { DAD010: record.DAD010, DAD090: '2' },
      })
      .then(resdata => {
        if (resdata.code < 1) {
          this.msgSrv.error(resdata.errmsg);
        } else {
          this.msgSrv.info('该事项已被接收');
          this.query();
        }
      });
  }
  //任务拒绝过程
  rwjj(record) {
    this.lbservice
      .lbservice('rwjj_update', {
        para: { DAD010: record.DAD010, DAD090: '2' },
      })
      .then(resdata => {
        if (resdata.code < 1) {
          this.msgSrv.error(resdata.errmsg);
        } else {
          this.msgSrv.info('该事项已被拒绝');
          this.query();
        }
      });
  }
}
